//using System;
//using System.Collections.Generic;
//using System.Text;
//using System.Security.Cryptography;
//using System.IO;
//namespace InfraStructureLayer
//{
//    public  class Crypto
//    {
//        SymmetricAlgorithm mCSP;
//        public Crypto()
//        {
            
//            //mCSP.IV = Convert.FromBase64String(_IV);
//            //mCSP.Key = Convert.FromBase64String(_key);
//        }
//        private string SetLengthString(string str, int length)
//        {
//            while (length > str.Length)
//            {
//                str += str;
//            }
//            if (str.Length > length)
//            {
//                str = str.Remove(length);
//            }
//            return str;
//        }
//        public string EncryptURL(string toEncrypt)
//        {
//            string key = "";
//            try
//            {
//                byte[] keyArray;
//                byte[] toEncryptArray = Encoding.GetEncoding("iso-8859-9").GetBytes(toEncrypt);

//                key = SetLengthString(CurrentContext.Parameters["Key"].ToString(), 16);

//                keyArray = Encoding.GetEncoding("iso-8859-9").GetBytes(key);

//                TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
//                tdes.Key = keyArray;
//                tdes.Mode = CipherMode.ECB;
//                tdes.Padding = PaddingMode.PKCS7;

//                ICryptoTransform cTransform = tdes.CreateEncryptor();

//                byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
//                tdes.Clear();
//                string s= System.Web.HttpUtility.UrlEncode(Convert.ToBase64String(resultArray, 0, resultArray.Length),Encoding.GetEncoding("iso-8859-9"));
//                CurrentContext.CryptoKeys[s]= toEncrypt;
//                return s;
//            }
//            catch (Exception ex)
//            {
//                throw (new SFBusinessException("An error occurred while encrypting string. Key was " + key + ".Exception " + ex.ToString()));
//            }
//        }
//        public string DecryptURL(string cipherString)
//        {
//            string key = "";
//            string cipherStringOriginal = cipherString;
//            try
//            {
//                cipherString = System.Web.HttpUtility.UrlDecode(cipherString, Encoding.GetEncoding("iso-8859-9"));
//                byte[] keyArray;
//                byte[] toEncryptArray = Convert.FromBase64String(cipherString.Replace(" ","+"));
//                key = SetLengthString(CurrentContext.Parameters["Key"].ToString(), 16);
//                keyArray = Encoding.GetEncoding("iso-8859-9").GetBytes(key);

//                TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
//                tdes.Key = keyArray;
//                tdes.Mode = CipherMode.ECB;
//                tdes.Padding = PaddingMode.PKCS7;

//                ICryptoTransform cTransform = tdes.CreateDecryptor();
//                byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
//                tdes.Clear();
//                return Encoding.GetEncoding("iso-8859-9").GetString(resultArray);
//            }
//            catch (Exception ex)
//            {
//                if (CurrentContext.CryptoKeys[cipherStringOriginal] != null)
//                {
//                    throw (new SFBusinessException("An error occurred while decrypting string. Referrer was " + System.Web.HttpContext.Current.Request.UrlReferrer + "Data was: " + CurrentContext.CryptoKeys[cipherStringOriginal].ToString() + ".Exception " + ex.ToString()));
//                }
//                else
//                {
//                    throw (new SFBusinessException("An error occurred while decrypting string. Referrer was " + System.Web.HttpContext.Current.Request.UrlReferrer + "Data was: " + cipherStringOriginal.ToString() + ".Exception " + ex.ToString()));
//                }
//            }
            
//        }

//    }
//}
